<template>
	<view class="content">
		<input class="input" type="text" placeholder="请输入意见反馈标题" @input="getTitle">
		<view class="split"></view>
		<textarea class="textarea" placeholder="请输入反馈内容" @input="getContents"/>
		<view class="split"></view>
		<view class="addBox textCenter" @tap="addBtn">
			<image class="icon_camera" src="/pages_mine/pages/static/order/icon_1.png" mode=""></image>
			<!-- <image class="icon_camera" src="../../static/order/icon_1.png" mode=""></image> -->
			<view class="name fontSize12">添加照片</view>
		</view>
		<image class="images" :src="item.src" mode="" v-for="(item,index) in imageBox" :key="index"></image>
		<view class="clearBoth"></view>
		<view class="split"></view>
		<input class="input" type="text" placeholder="请输入你的姓名" @input="getName">
		<view class="split"></view>
		<input class="input" type="number" placeholder="请输入你的联系方式" maxlength="11" @input="getTel">
		<view class="split"></view>
		
		<view class="btnSure" @tap="getSure">立即提交</view>
	</view>
</template>
<style>
	.content{}
	.content .input{width:90%;margin-left: 2.5%;padding:2.5%;}
	.content .textarea{width:90%;margin-left: 2.5%;padding:2.5%;}
	.content .uni-input-placeholder{font-size: 14px;}
	.content .uni-textarea-placeholder{font-size: 14px;}
	.content .addBox{width:150upx;height:160upx;margin-top: 20upx;margin-bottom: 20upx;line-height: 55upx;margin-left: 5%;float: left;padding-top:20upx;border:1px dashed #CCCCCC;border-radius: 10upx;}
	.content .addBox .icon_camera{width:56upx;height:56upx;}
	.content .addBox .name{color:#CCCCCC}
	.content .images{width:150upx;height: 150upx;margin-top: 20upx;margin-bottom: 20upx;margin-left: 6%;float: left;border-radius: 10upx;}
	.content .split{width:90%;height:2upx;margin-left: 5%;background: #F2F2F5;}
	.content .btnSure{width:90%;font-size: 16px;text-align: center;padding:2.5%;background: #DC582A;color:white;border-radius: 100upx;position: fixed;left: 5%;bottom:50upx}
</style>
<script>
	import Share from '@/common/wx_share.js'
	export default {
		data() {
			return {
				share:{
					title:"",
					path:'/pages/tabbar/mine',
					imageUrl:'',
					desc:'',
					content:''
				},
				data:{"contents":"","title":"","name":"","tel":""},
				imageBox:[],
				imageBoxs:[],
				imageToken:"",
				imageSrc:"",
			}
		},
		onLoad(){
			this.AjaxGetToken();
		},
		methods: {
			AjaxGetToken(){
				let param={
					token:this._$userToken("userInfo").token
				};
				this._$InitRequest.request('index/get_token', param).then(res => {
					this.imageToken = res.data.token
					this.imageSrc = res.data.domain + "/"
				},error=>{})
			},
			getTitle(e){this.data.title = e.target.value},
			getContents(e){this.data.contents = e.target.value},
			getName(e){this.data.name = e.target.value},
			getTel(e){this.data.tel = e.target.value},
			addBtn(){
				var that = this;
				uni.chooseImage({
				    count: 1,
				    sizeType: ['original', 'compressed'],
				    sourceType: ['album'],
				    success: function (res) {
						uni.showLoading({
							title:"正在上传..."
						})
						uni.uploadFile({
							url:"https://upload.qiniup.com",
							header:{},
							filePath:res.tempFilePaths[0],
							name: 'file',
							formData: {
								'token':that.imageToken
							},
							success: (res) => {
								var imageUrl = that.imageSrc + JSON.parse( res.data ).key
								var src = {'src':imageUrl}
								if( that.imageBox.length > 2 ){
									uni.showToast({icon:'none',title:'抱歉，最多只能上传三张图片'})
									return;
								}else{
									that.imageBox.push(src)
									that.imageBoxs.push(imageUrl)
								}
								uni.hideLoading()
							},
						});
				    }
				});
			},
			getSure(){
				var imageBox = []
				this.imageBoxs.forEach((item)=>{
					imageBox.push( item.split( this.imageSrc )[1] )
				})
				imageBox = imageBox.toString()
				let param={
					token:this._$userToken("userInfo").token,
					title:this.data.title,
					username:this.data.name,
					phone:this.data.tel,
					content:this.data.contents,
					image:imageBox,
				};
				this._$InitRequest.request('MemberInfo/feedback', param).then(res => {
					uni.showToast({icon:'none',title:res.msg})
					if( res.status == 200 ){
						setTimeout(function(){
							uni.switchTab({url:"/pages/tabbar/mine"})
						},1500)
					}
				},error=>{})
			},
			
		}
	}
</script>